package tdd.t1;

public class TaxiFee {
	protected int iStartMiles;
	protected int iDaytimeStartTime;
	protected double dDaytimePricePerMile;
	protected double dDaytimeStartPrice;
	protected int iNightStartTime;
	protected double dNightPricePerMile;
	protected double dNightStartPrice;
    
    TaxiFee() {
    	this(3,6,1.6,11.0,23,2.4,13);
    }
    
    TaxiFee(int iStartMiles,
    		int iDaytimeStartTime,
    		double dDaytimePricePerMile,
    		double dDaytimeStartPrice,
    		int iNightStartTime,
    		double dNightPricePerMile,
    		double dNightStartPrice) {
    	this.iStartMiles = iStartMiles;	
    	this.iDaytimeStartTime = iDaytimeStartTime;
    	this.dDaytimePricePerMile = dDaytimePricePerMile;
    	this.dDaytimeStartPrice = dDaytimeStartPrice;
    	this.iNightStartTime = iNightStartTime;
    	this.dNightPricePerMile = dNightPricePerMile;
    	this.dNightStartPrice = dNightStartPrice;
    }
    
    private double charge(double miles,  double unitFee, double startPrice) {
		return  Math.ceil(miles) <= this.iStartMiles? startPrice: (Math.ceil(miles) - this.iStartMiles)*unitFee+startPrice;   
    }
    
    public double chargeByTime(double miles, int time) throws Exception {
    	if(miles<0||time<0||time>24) {
    		throw new Exception();
    	} 
    	   	
    	if(time>=this.iDaytimeStartTime&&time<this.iNightStartTime) {
    		return this.charge(miles, this.dDaytimePricePerMile, this.dDaytimeStartPrice);
   		} else {
    		return this.charge(miles, this.dNightPricePerMile, this.dNightStartPrice);
    	}
    }
    
    public String name() {
		 return getClass().getSimpleName();
	 }
    
}
